<%@ Page Title="" Language="C#" MasterPageFile="~/Hierarchy.Master" AutoEventWireup="true" CodeBehind="KPIGroupList.aspx.cs" Inherits="KPIBalanceScoreCard.KPIGroupList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<%
    if (Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()] != null && !"".Equals( Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()].ToString().Trim()))
  { %>


    <%//= "<script type=\"text/javascript\" > function highLight() { var groupName = '" + Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()] + "' ; document.getElementById(groupName).style.color = 'Green';  document.getElementById(groupName).style.font-weight = 'bolder';  } </script> "%>
    
   
   <script type="text/javascript" >

    //   highLight();
   </script> 

<%
} %>
    <script type ="text/javascript" >
        function itemGroup(groupName) {
           
            document.getElementById("ctl00_ContentPlaceHolder1_itemGroupName").value = groupName;
            //alert(document.getElementById(groupName).style);
        }
    
    </script>


<asp:HiddenField ID="itemGroupName" runat ="server" Value = "1.Business Target" EnableViewState="false"/>
    <table>
        <% if(Session[KPIBalanceScoreCard.ApplicationConstants.CURRENT_ROLE.ToString()] != null && Session[KPIBalanceScoreCard.ApplicationConstants.CURRENT_ROLE.ToString()].ToString().Equals(KPIBalanceScoreCard.ApplicationStrings.AREA_MGR)) { %>
        <tr>
            <td bgcolor="#3399FF">
                <asp:Button ID="showAllDetails" runat="server" Text="Score Card By Role" 
                    PostBackUrl="AreaMgrDetails.aspx" onclick="showAllDetails_Click" />
            </td>
        </tr>
        <%} %>
        <tr>
            <td>
                                Year
                <asp:DropDownList ID="yearDropDown" runat="server" 
                    DataSourceID="YearDataSource" DataTextField="Year" DataValueField="Year" 
                                    AutoPostBack="True" onselectedindexchanged="yearDropDown_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:SqlDataSource ID="YearDataSource" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:kpibalancescorecardConnectionString %>" 
                    SelectCommand="SELECT DISTINCT Year FROM Balance ORDER BY Year desc"></asp:SqlDataSource>
            </td>
            <td>
                Month
                <asp:DropDownList ID="monthDropDown" runat="server" 
                    DataSourceID="MonthDataSource" DataTextField="Month" 
                    DataValueField="Month" AutoPostBack="True" 
                    onselectedindexchanged="monthDropDown_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:SqlDataSource ID="MonthDataSource" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:kpibalancescorecardConnectionString %>" 
                    SelectCommand="SELECT DISTINCT Month FROM Balance ORDER BY Month desc"></asp:SqlDataSource>
            &nbsp;</td>
        </tr>
        
    </table>
           

<% if (Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_GROUPS.ToString()] != null)
   {%>
    <table>
        <tr>
            <th> Score Card </th>
            <%
    KPIBalanceScoreCard.HierarchyDataset.ItemGroupsDataTable itemGroupDt = new KPIBalanceScoreCard.HierarchyDataset.ItemGroupsDataTable();


    itemGroupDt = (KPIBalanceScoreCard.HierarchyDataset.ItemGroupsDataTable)Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_GROUPS.ToString()];

    foreach (KPIBalanceScoreCard.HierarchyDataset.ItemGroupsRow itemGroupDr in itemGroupDt.Rows)
    {%>
            <th>               
               <input style="background-color:Olive; width :150px; font-size:medium" id="<%= itemGroupDr.ItemGroup %>" type="submit" onclick = "itemGroup('<%= itemGroupDr.ItemGroup %>');" value = "<%= itemGroupDr.ItemGroup %>" />               
            </th>  
            <% 
    }
   
                 %>         
        </tr>
    </table>
   <%} %> 
   <hr />
   
 <!-- 
 
    <%if (Session[KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_NODE_VALUE.ToString()] != null && !"".Equals(Session[KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_NODE_VALUE.ToString()].ToString()))
      { %>
        
     <table>
        <tr>
            <th>
                Name: <%= Session [KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_NODE_VALUE.ToString()] == null ? "Nothing Selected Yet. Please click the tree on Left hand side>" : Session[KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_NODE_VALUE.ToString()] %>
            
            </th>
        </tr>
        
    </table>
    <%} %>
 
 -->
    
<!-- 

    <table>
        <tr>
            <td>
            
                <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
            
            </td>        
        </tr>
    
    </table>
-->
    
    
    <%if(Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()]!= null && !"".Equals(Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()].ToString())) { %>
        
     <table>
        <tr>
            <td>
                <%= Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()] == null ? "Nothing selected yet" : Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()]%> 
            </td>
        </tr>        
    </table>
    <hr />

<%
    if (Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_EMPNAME.ToString()] != null)
    {

        KPIBalanceScoreCard.HierarchyDataset.EmpDetailsDataTable dt = new KPIBalanceScoreCard.HierarchyDatasetTableAdapters.EmpDetailsTableAdapter().GetData(Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_EMPNAME.ToString()].ToString(), Double.Parse(Session[KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_YEAR.ToString()].ToString()), Double.Parse(Session[KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_MONTH.ToString()].ToString()));
        if (dt != null && dt.Rows.Count > 0)
        { 
           %>

     <table>
        <tr>
            <th>
           Name 
            </th>
            <td>
            <%= dt.Rows[0][0]%>
            </td>
            
              <th>
           Role
            </th>
            <td>
            <%= dt.Rows[0][1]%>
            </td>
        
            <th>
           Staff Id
            </th>
            <td>
            <%= dt.Rows[0][2]%>
            </td>
        </tr>        
        
        <tr>    
              <th>
           Branch Name
            </th>
            <td>
            <%= dt.Rows[0][3]%>
            </td>
       
            <th>
           Area Name
            </th>
            <td>
            <%= dt.Rows[0][4]%>
            </td>
            
              <th>
           Account Number
            </th>
            <td>
            <%= dt.Rows[0][5]%>
            </td>
        </tr>        
        
    </table>
    <hr />
   
   <%}
    }
    else if (Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ROLE.ToString()] != null)
    {

        KPIBalanceScoreCard.HierarchyDataset.RoleDetailsDataTable dt = new KPIBalanceScoreCard.HierarchyDatasetTableAdapters.RoleDetailsTableAdapter().GetData(Session[KPIBalanceScoreCard.ApplicationConstants.ORGANIZATION_NAME.ToString()].ToString(), Double.Parse(Session[KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_YEAR.ToString()].ToString()), Double.Parse(Session[KPIBalanceScoreCard.ApplicationConstants.CHOOSEN_MONTH.ToString()].ToString()));
        if (dt != null && dt.Rows.Count > 0)
        { 
           %>

     <table>
        <tr>
            <th>
           Name 
            </th>
            <td>
            <%//= dt.Rows[0][0]%>
            <%= Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ROLE.ToString()]%>
            </td>
            <th>
           Branch Name 
            </th>
            <td>
            <%//= dt.Rows[0][1]%>
            <%= Session[KPIBalanceScoreCard.ApplicationConstants.ORGANIZATION_NAME.ToString()] %>
            </td>
        </tr>    
        
        <tr>
            <th>
           Area Name 
            </th>
            <td>
            <%= dt.Rows[0][0]%>
            </td>
        </tr>    
        
            
    </table>
    <hr />
   
   <%}
    } %>
      
    <table>
        <tr>
        <td valign="top">
        <table width="100%" >
           
            <tr >
                <th align="center">
                 MTD
                </th>
            </tr>
        </table>
        <table border="1">
            <tr>
            <th>Item Name</th>
            <td>|</td>
            <th>Actual</th>
            <th>Target</th>
            <th>%</th>
            <th>Weight</th>
            <th>Score</th>
            </tr>
            <%if (Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_MTD.ToString()] != null)
              {
                  KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable detailsDtMTD = (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable)Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_MTD.ToString()];

                  foreach (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsRow detailsRow in detailsDtMTD.Rows)
                  {                
                  %>
            <tr>
                <td nowrap="nowrap"><%= detailsRow.ItemName %> </td>
                <td>|</td>
                <td><%= detailsRow.actual %></td>
                <td><%= detailsRow.budget %></td>
                <% double actual = double.Parse(detailsRow.actual.ToString());
                   double budget = double.Parse(detailsRow.budget.ToString());
                   if (budget == 0)
                   {
                       budget = actual;
                   }
                   double result = (actual / budget) * 100;                  
                %>
                                
                <td style ="color:<%= result < 80 ? "White" : result > 80 && result < 89.99 ? "BLACK" : result > 90 && result < 95.99 ? "White" : "White"%>; background-color:<%= result < 80 ? "Red" : result > 80 && result < 89.99 ? "YELLOW" : result > 90 && result < 95.99 ? "GREEN" : "BLUE"%>"><%= actual == 0 ? 00.00: Math.Round(result,2)%></td>
                <td><%= detailsRow.weight %></td>
                <td><%= detailsRow.score %></td>        
            </tr>
            <%}
              } %>
        </table>
   </td>
   
   <td valign="top">
        <table width="100%">
            <tr>            
                <th  align="center">
                YTD
                </th>
            </tr>
            
        </table>
    
        <table border="1">
            <tr>
           <!--  <th>Item Name</th> -->
           
            <th>Actual</th>
            <th>Target</th>
            <th>%</th>
            <th>Weight</th>
            <th>Score</th>
            </tr>
            <%if (Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_YTD.ToString()] != null)
              {
                  KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable detailsDtYTD = (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable)Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_YTD.ToString()];
                  foreach (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsRow detailsRow in detailsDtYTD.Rows)
                  {                
                  %>
            <tr>
                <!-- <td><%= detailsRow.ItemName %></td> -->
               
                <td><%= detailsRow.actual %></td>
                <td><%= detailsRow.budget %></td>
                <% double actual = double.Parse(detailsRow.actual.ToString());
                   double budget = double.Parse(detailsRow.budget.ToString());
                   if (budget == 0)
                   {
                       budget = actual;
                   }
                   double result = Math.Round((actual / budget) * 100, 2);
                      
                %>
                
                <td style ="color:<%= result < 80 ? "White" : result > 80 && result < 89.99 ? "BLACK" : result > 90 && result < 95.99 ? "White" : "White"%>; background-color:<%= result < 80 ? "Red" : result > 80 && result < 89.99 ? "YELLOW" : result > 90 && result < 95.99 ? "GREEN" : "BLUE"%>"><%=  actual == 0 ? 00.00 : result %></td>
                <td><%= detailsRow.weight %></td>
                <td><%= detailsRow.score %></td>        
            </tr>
            <%}
            } %>
        </table>
    </td>
    </tr>
    </table>    
    
    <%}

      Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_MTD.ToString()] = new KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable();
      Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_YTD.ToString()] = new KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable();
        
        %>
</asp:Content>
